export interface FileType {
  extensions: string[]
  icon: any
  maxSize: number
  label: string
}

export interface FileTypes {
  [key: string]: FileType
}

export const FILE_TYPES: FileTypes = {
  image: {
    extensions: ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'],
    icon: "Picture",
    maxSize: 10 * 1024 * 1024, // 10MB
    label: '图片'
  },
  document: {
    extensions: ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf', 'txt'],
    icon: "Document",
    maxSize: 20 * 1024 * 1024, // 20MB
    label: '文档'
  },
  video: {
    extensions: ['mp4', 'webm', 'ogg', 'mov', 'avi'],
    icon: "VideoPlay",
    maxSize: 100 * 1024 * 1024, // 100MB
    label: '视频'
  },
  audio: {
    extensions: ['mp3', 'wav', 'ogg', 'aac'],
    icon: "Headset",
    maxSize: 20 * 1024 * 1024, // 20MB
    label: '音频'
  },
  archive: {
    extensions: ['zip', 'rar', '7z', 'tar', 'gz'],
    icon: "FolderDelete",
    maxSize: 100 * 1024 * 1024, // 100MB
    label: '压缩包'
  },
  code: {
    extensions: ['js', 'ts', 'html', 'css', 'json', 'php', 'java', 'py', 'go', 'vue'],
    icon: "Monitor",
    maxSize: 5 * 1024 * 1024, // 5MB
    label: '代码'
  }
}

// 获取文件类型信息
export const getFileType = (suffix: string) => {
  suffix = suffix.toLowerCase().replace('.', '')
  for (const [type, config] of Object.entries(FILE_TYPES)) {
    if (config.extensions.includes(suffix)) {
      return { type, config }
    }
  }
  return { 
    type: 'other', 
    config: { 
      icon: "Files", 
      maxSize: 50 * 1024 * 1024, 
      label: '其他', 
      extensions: [] 
    } 
  }
}

// 格式化文件大小
export const formatFileSize = (size?: number) => {
  if (!size) return '0 B'
  if (size < 1024) return size + ' B'
  if (size < 1024 * 1024) return (size / 1024).toFixed(2) + ' KB'
  if (size < 1024 * 1024 * 1024) return (size / 1024 / 1024).toFixed(2) + ' MB'
  return (size / 1024 / 1024 / 1024).toFixed(2) + ' GB'
}

// 获取文件分组
export const getFileGroup = (suffix?: string) => {
  if (!suffix) return '其他'
  const { config } = getFileType(suffix)
  return config.label
} 